package com.ziyun.erp.web.api.freightages;

import com.ziyun.erp.modules.freightages.entity.SdbEctoolsRegionsEntity;
import com.ziyun.erp.modules.freightages.service.SdbEctoolsRegionsService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import net.sf.json.JSONArray;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 
 *
 * @author 
 * @email 
 * @date 2018-08-10 15:38:32
 */
@RestController
@RequestMapping("port/freightages/sdbectoolsregions")
public class SdbEctoolsRegionsApi {
    @Autowired
    private SdbEctoolsRegionsService sdbEctoolsRegionsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("freightages:sdbectoolsregions:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sdbEctoolsRegionsService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{regionId}")
    @RequiresPermissions("freightages:sdbectoolsregions:info")
    public R info(@PathVariable("regionId") Integer regionId){
        SdbEctoolsRegionsEntity sdbEctoolsRegions = sdbEctoolsRegionsService.selectById(regionId);

        return R.ok().put("sdbEctoolsRegions", sdbEctoolsRegions);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("freightages:sdbectoolsregions:save")
    public R save(@RequestBody SdbEctoolsRegionsEntity sdbEctoolsRegions){
        sdbEctoolsRegionsService.insert(sdbEctoolsRegions);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("freightages:sdbectoolsregions:update")
    public R update(@RequestBody SdbEctoolsRegionsEntity sdbEctoolsRegions){
        ValidatorUtils.validateEntity(sdbEctoolsRegions);
        sdbEctoolsRegionsService.updateAllColumnById(sdbEctoolsRegions);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("freightages:sdbectoolsregions:delete")
    public R delete(@RequestBody Integer[] regionIds){
        sdbEctoolsRegionsService.deleteBatchIds(Arrays.asList(regionIds));

        return R.ok();
    }

    /**
     * 查询省市区级联数据
     * @return
     */
    @RequestMapping("/queryRegionsSascade")
    public R queryRegionsSascade(){
        // 查询省市区级联数据
        List<String> result = sdbEctoolsRegionsService.queryRegionsSascade();
        return R.ok().put("list", JSONArray.fromObject(result).toString());
    }

}
